package com.chun.service.impl;

import com.chun.mapper.ClazzMapper;
import com.chun.pojo.Clazz;
import com.chun.pojo.PageBean;
import com.chun.service.ClazzService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * Clazz逻辑实现类
 */
@Service
public class ClazzServiceImpl implements ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;

    @Override
    public PageBean getClazzs(String name, Date begin, Date end, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Clazz> clazzList = clazzMapper.getClazzs(name, begin, end);
        Page<Clazz> pages = (Page<Clazz>) clazzList;
        PageBean pageBean = new PageBean(pages.getTotal(), pages.getResult());
        return pageBean;
    }

    @Override
    public void deleteClazzById(Integer id) {
        clazzMapper.deleteClazzById(id);
    }

    @Override
    public void addClazz(Clazz clazz) {
        clazz.setCreateTime(LocalDateTime.now());
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.addClazz(clazz);
    }

    @Override
    public Clazz getClazzById(Integer id) {
        Clazz clazz = clazzMapper.getClazzById(id);
        return clazz;
    }

    @Override
    public void updateClazz(Clazz clazz) {
        clazzMapper.updateClazz(clazz);
    }

    @Override
    public List<Clazz> getClazzList() {
        List<Clazz> clazzList = clazzMapper.getClazzList();
        return clazzList;
    }
}
